﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using LibNiconico.NiconicoApi.Internal;
using LibNiconico.NiconicoApi.Extentions;

namespace LibNiconico.NiconicoApi.PlayerStatus
{

    public sealed partial class NicoPlayerStatus
    {
        public sealed partial class InternalClasses
        {
            public sealed partial class User
            {
                /// <summary>
                /// ユーザID
                /// </summary>
                public string UserId { get; private set; }

                /// <summary>
                /// ニックネーム
                /// </summary>
                public string NickName { get; private set; }

                /// <summary>
                /// プレミアム判定
                /// </summary>
                public bool IsPremium { get; private set; }

                /// <summary>
                /// ユーザの年齢
                /// </summary>
                public int UserAge { get; private set; }

                /// <summary>
                /// ユーザの性別
                /// </summary>
                public int UserSex { get; private set; }

                /// <summary>
                /// ユーザの国?
                /// </summary>
                public string UserDomain { get; private set; }

                /// <summary>
                /// ユーザの都道府県?
                /// </summary>
                public int UserPrefecture { get; private set; }

                /// <summary>
                /// ユーザが使用する言語
                /// </summary>
                public string UserLanguage { get; private set; }

                /// <summary>
                /// 部屋名
                /// </summary>
                public string RoomLabel { get; private set; }

                /// <summary>
                /// 席番号
                /// </summary>
                public int RoomSeetNo { get; private set; }

                /// <summary>
                /// 不明
                /// </summary>
                public bool IsJoin { get; private set; }

                /// <summary>
                /// ユーザのツイッター情報
                /// </summary>
                public InternalClasses.TwitterInfo TwitterInfo { get; private set; }



                internal static User Parse(XElement element)
                {
                    return XElementExtention.Parse(element, "user", item =>
                    {
                        return new User
                        {
                            UserId = XElementExtention.GetElementAsString(item, "user_id"),
                            NickName = XElementExtention.GetElementAsString(item, "nickname"),
                            IsPremium = XElementExtention.GetElementAsBool(item, "is_premium"),
                            UserAge = XElementExtention.GetElementAsInt(item, "userAge"),
                            UserSex = XElementExtention.GetAttributeAsInt(item, "userSex"),
                            UserDomain = XElementExtention.GetElementAsString(item, "userDomain"),
                            UserPrefecture = XElementExtention.GetElementAsInt(item, "userPrefecture"),
                            UserLanguage = XElementExtention.GetElementAsString(item,"userLanguage"),
                            RoomLabel = XElementExtention.GetElementAsString(item, "room_label"),
                            RoomSeetNo = XElementExtention.GetElementAsInt(item, "room_seetno"),
                            IsJoin = XElementExtention.GetElementAsBool(item, "is_join"),
                            TwitterInfo = InternalClasses.TwitterInfo.Parse(item)
                        };
                    }) ?? new User();

                }

                internal User() 
                {
                    this.UserAge = 0;
                    this.UserDomain = "";
                    this.UserId = "";
                    this.NickName = "";
                    this.IsPremium = false;
                    this.UserSex = 0;
                    this.UserPrefecture = 0;
                    this.UserLanguage = "";
                    this.IsJoin = false;
                    this.RoomLabel = "";
                    this.RoomSeetNo = 0;
                    this.TwitterInfo = new InternalClasses.TwitterInfo();

                }
            }
        }
    }
}
